limsBatchRevise.auditPage = {

    getGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-batch-revise-audit-list-grid',
            url: limsBatchRevise.baseUrl + '/queries/tasks',
            requestData: {
                // status_EQ: 'approve'
            },
            service: 'limsBatchReviseServiceImpl',
            dbTable: 'T_LIMS_BATCH_REVISE',
            columns: limsBatchRevise.getEditListColumns(),
            deleteFormatter: function (row) {
                return row.batchCode || row.id;
            },
            onCellClick: function (field, row) {
                field === 'batchCode' && _this.loadDetailPage(row);
            },
            page: true,
            toolbar: [/*{
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.PASS',
                icon: 'pass',
                onClick: function () {
                    var selections = Gikam.getComp('lims-batch-revise-audit-list-grid').getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }
                    var submitUrl = limsBatchRevise.baseUrl + '/approve';
                    Gikam.confirm('GIKAM.WORKFLOW.BUTTON.PASS', 'GIKAM.TIP.SUBMIT', function () {
                        workspace.window.showMask()
                        Gikam.postText(submitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function () {
                            Gikam.getComp('lims-batch-revise-audit-list-grid').refresh();
                        }).always(function () {
                            workspace.window.closeMask()
                        })
                    })
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.REJECT',
                icon: 'reject',
                onClick: function () {
                    var selections = Gikam.getComp('lims-batch-revise-audit-list-grid').getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }
                    var submitUrl = limsBatchRevise.baseUrl + '/reject';
                    Gikam.confirm('GIKAM.WORKFLOW.BUTTON.REJECT', 'GIKAM.TIP.SUBMIT', function () {
                        workspace.window.showMask()
                        Gikam.postText(submitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function () {
                            Gikam.getComp('lims-batch-revise-audit-list-grid').refresh();
                        }).always(function () {
                            workspace.window.closeMask()
                        })
                    })
                }
            }, */{// 换成工作流的
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.PASS',
                icon: 'pass',
                onClick: function () {
                    _this.pass();
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.REJECT',
                icon: 'reject',
                onClick: function () {
                    _this.reject();
                }
            }]
        }
    },

    pass: function () {
        let _this = this
        var grid = Gikam.getComp('lims-batch-revise-audit-list-grid')
        Gikam.create('workflow').pass({
            data: grid.getSelections(),
            pageObject: limsBatchRevise,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            grid.refresh()
        })
    },

    reject: function () {
        let _this = this
        var grid = Gikam.getComp('lims-batch-revise-audit-list-grid')
        Gikam.create('workflow').reject({
            data: grid.getSelections(),
            pageObject: limsBatchRevise,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            grid.refresh()
        })
    },

    loadDetailPage: function (row) {
        workspace.window.load(limsBatchRevise.baseUrl + '/page/detail' + Gikam.param({
            id: row.id,
            batchId: row.batchId,
            reviseType: row.reviseType,
            audit: '1',
            readonly: '1',
            processStatus: row.processStatus
        }));
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-batch-revise-audit-list-layout',
            renderTo: workspace.window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        });
    },

    init: function () {
        this.create();
    }
};
